package com.activenetwork.smlite.testcase.login;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Test;

import com.activenetwork.smlite.page.LoginErrorPage;
import com.activenetwork.smlite.testcase.BaseCase;
import com.activenetwork.util.EnvContext;
import com.activenetwork.util.PageLoader;
import com.activenetwork.util.verification.gson.FailurePoint;

public class Login010 extends BaseCase {
	static final Logger logger = LoggerFactory.getLogger(Login010.class);
	
	@Test
	public void Check_user_cant_sign_in_with_invalid_username_or_password(){
		
		
		// invalid user name & invalid password
		loginBusiness.login("wrong_user", "password");
		LoginErrorPage loginErrorPage = PageLoader.load(LoginErrorPage.class);
		if(!StringUtils.endsWithIgnoreCase(loginErrorPage.getErrorMsg(), "Username or Password is not correct.")){
			EnvContext.failurePointTL.get().add(new FailurePoint(
					Login010.class.getName(), 
					"Verify incorrect user can not sign in", 
					"Incorrect error message for sign in failure"));
		}
		
		// valid user name & invalid password
		loginBusiness.login("autotest1@activenetwork.com", "password");
		loginErrorPage = PageLoader.load(LoginErrorPage.class);
		if(!StringUtils.endsWithIgnoreCase(loginErrorPage.getErrorMsg(), "Username or Password is not correct.")){
			EnvContext.failurePointTL.get().add(new FailurePoint(
					Login010.class.getName(), 
					"Verify incorrect password can not sign in", 
					"Incorrect error message for sign in failure"));
		}
		
		// empty user name & empty password
		loginBusiness.login("", "");
		loginErrorPage = PageLoader.load(LoginErrorPage.class);
		if(!StringUtils.endsWithIgnoreCase(loginErrorPage.getErrorMsg(), "Please provide a username and password to login.")){
			EnvContext.failurePointTL.get().add(new FailurePoint(
					Login010.class.getName(), 
					"Verify empty user name & empty password can not sign in", 
					"Incorrect error message for sign in failure"));
		}
		
		// valid user name & empty password
		loginBusiness.login("autotest1@activenetwork.com", "");
		loginErrorPage = PageLoader.load(LoginErrorPage.class);
		if(!StringUtils.endsWithIgnoreCase(loginErrorPage.getErrorMsg(), "Please provide a username and password to login.")){
			EnvContext.failurePointTL.get().add(new FailurePoint(
					Login010.class.getName(), 
					"Verify valid user name & empty password can not sign in", 
					"Incorrect error message for sign in failure"));
		}
		
		
		// empty user name & valid password
		loginBusiness.login("", "st@rc!te");
		loginErrorPage = PageLoader.load(LoginErrorPage.class);
		if(!StringUtils.endsWithIgnoreCase(loginErrorPage.getErrorMsg(), "Please provide a username and password to login.")){
			EnvContext.failurePointTL.get().add(new FailurePoint(
					Login010.class.getName(), 
					"Verify empty user name & valid password can not sign in", 
					"Incorrect error message for sign in failure"));
		}

		
		loginBusiness.logout();
		
	}
	
	

}
